﻿using System;
using System.Linq;
using System.Reflection;
using Windows.Storage;
using Windows.UI.Xaml.Controls;
using XamlInspector.Model;

namespace XamlInspector.Presentation
{
    public class XamlViewModel : ViewModelBase
    {
        private string _xamlSource;

        public async void UpdateSelectedElement(XamlElement element)
        {
            XamlSource = null;

            if (element == null)
            {
                return;
            }

            var baseUriProperty = element.Properties.FirstOrDefault(p => p.Name.StartsWith("BaseUri"));
            if (baseUriProperty != null)
            {
                var baseUri = baseUriProperty.TextValue;
                if (string.IsNullOrWhiteSpace(baseUri) == false)
                {
                    //var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(baseUri.Replace("/", "///WindowsStoreTestClient/")));
                    //XamlSource = await FileIO.ReadTextAsync(file);
                }
            }

        }

        public string XamlSource
        {
            get { return _xamlSource; }
            set { ChangeAndNotify(value, ref _xamlSource); }
        }
    }
}
